﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using YasharEl.Infrastructure.EntityModel.Specifications;
using YasharEl.Infrastructure.EntityModel;
using System.Linq.Expressions;

namespace YasharEl.Infrastructure.TaskEngine.PersistenceModel.Specifications
{
    [ContractClass(typeof(TaskSpecificationContract))]
    public interface ITaskSpecification : ISpecification<ITask, long>
    {
        ITaskSpecification AssignedTo(long userId);

        ITaskSpecification WithName(string name);

        ITaskSpecification RelatedToInitiator(Guid initiatorCorrelator);
    }

    [ContractClassFor(typeof(ITaskSpecification))]
    internal abstract class TaskSpecificationContract : ITaskSpecification
    {
        public ITaskSpecification AssignedTo(long userId)
        {
            Contract.Requires<ArgumentNullException>(userId > 0, "userId must be valid positive numeric value.");
            return this;
        }

        public ITaskSpecification WithName(string name)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(name), "name could not be null or empty.");
            return this;
        }

        public ITaskSpecification RelatedToInitiator(Guid initiatorCorrelator)
        {
            Contract.Requires<ArgumentNullException>(initiatorCorrelator != Guid.Empty, "initiatorCorrelator could not be null.");
            return this;
        }

        public void Initialize(IUnitOfWork unitOfWork)
        {
            Contract.Requires<ArgumentNullException>(unitOfWork != null, "unitOfWork could not be null.");
        }

        public ISpecificationResult<ITask, long> ToResult()
        {
            return default(ISpecificationResult<ITask, long>);
        }

        public ISpecification<ITask, long> Where(Expression<Func<ITask, bool>> expression)
        {
            Contract.Requires<ArgumentNullException>(expression != null, "expression could not be null.");

            return default(ISpecification<ITask, long>);
        }
    }
}
